package com.example.teachingevaluationsystem.controller;

import com.example.teachingevaluationsystem.config.jwt.JwtConfigProperties;
import com.example.teachingevaluationsystem.service.IUserService;
import com.example.teachingevaluationsystem.vo.TokenVo;
import com.example.teachingevaluationsystem.vo.UserVo;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
@AllArgsConstructor
public class LoginController {
  private final IUserService userService;
  private final JwtConfigProperties jwtConfigProperties;

  @ApiOperation(value = "登录以后返回token")
  @PostMapping(value = "/login")
  public TokenVo login(@RequestBody UserVo userVo) {
    final String token = userService.login(userVo.getUsername(), userVo.getPassword());
    return new TokenVo(jwtConfigProperties.getTokenHead(), token);
  }
}
